package first_gui.gui;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import first_gui.ui.UserMessages;

public class UserView extends JFrame {
	private JCheckBox checkbox;
	private JTextField firstName;
	private JTextField lastName;
	public UserView(){
		UserMessages userMessage = new UserMessages();
		JPanel panel = new JPanel(new BorderLayout());
		int numberOfRows = 3;
		int numberOfColumns = 2;
		panel.setLayout(new GridLayout(numberOfRows, numberOfColumns));
		JLabel firstNameLabel = new JLabel(userMessage.firstName());
		panel.add(firstNameLabel);
		firstName = new JTextField();
		panel.add(firstName);
		JLabel lastNameLabel = new JLabel(userMessage.lastName());
		panel.add(lastNameLabel);
		lastName = new JTextField();
		panel.add(lastName);
		JButton saySomething = new JButton(userMessage.saySomething());
		panel.add(saySomething);
		checkbox = new JCheckBox("Nice dude");
		panel.add(checkbox);
		getContentPane().add(panel);
		pack();
		saySomething.setToolTipText(userMessage.saySomethingTwo());
		saySomething.addActionListener(new MyActionListener());
	}
	private class MyActionListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			if(!checkbox.isSelected()){
				JOptionPane.showMessageDialog(null, "I don't like you, " +
						firstName.getText() + " " + lastName.getText() + "!"
						);
			}
			else {
				JOptionPane.showMessageDialog(null, "How are you, " +
						firstName.getText() + " " + lastName.getText() + "?"
						);
			}
		}
	}
}